<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>51微贷</title>
		<link rel="stylesheet" type="text/css" href="../css/reset.css">
		<link rel="stylesheet" type="text/css" href="../css/common.css">
		<link rel="stylesheet" type="text/css" href="../css/icomoon/style.css">
		<script type="text/javascript" src="../js/rem.js"></script>
	</head>

	<body>
		<div class="m-common m-securitypwd">
			<div class="hd">
				<h3 class="title f-pr">
					<span>实名认证</span>
					<i class="icon-angle-left f-pa" @tap="back()"></i>
				</h3>
				<div class="avator">
					<img v-if="result" src="../images/avator-2.png">
					<img v-else src="../images/avator-1.png">
				</div>
				<p v-if="result">您已通过实名认证</p>
				<p v-else>您未通过实名认证</p>
			</div>
			<ul>
				<li>
					<label>真实姓名</label>
					<span v-if="result" class="f-fr">{{name}}</span>
					<template v-else>
						<input type="text" class="name" placeholder="请输入您的真实姓名">
						<i class="close-icon f-pa"></i>
					</template>
				</li>
				<li>
					<label>身份证号</label>
					<span v-if="result" class="f-fr">{{cardno}}</span>
					<template v-else>
						<input type="text" class="cardno" placeholder="请输入您的身份证号">
						<i class="close-icon f-pa"></i>
					</template>
				</li>
			</ul>
			<template v-if="!result">
				<div class="btn-box">
					<a class="btn">提交认证</a>
				</div>
			</template>
		</div>
		<script type="text/javascript" src="../js/md5.min.js"></script>
		<script type="text/javascript" src="../js/zepto.min.js"></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>

		<script type="text/javascript">
			mui.plusReady(function() {
				var vm = new Vue({
					el: '.m-common',
					data: {
						result: false,
						name: '',
						cardno: ''
					},
					methods: {
						back: function() {
							mui.back();
						}
					}
				});
				mui.ajax(base + 'account/authinfo', {
					type: 'get',
					data: {
						'id': parseInt(plus.storage.getItem('user_id'))
					},
					dataType: 'json',
					headers: sign(md5),
					success: function(data) {
						console.log('实名认证:' + JSON.stringify(data))
						vm.result = data.is_auth;
						vm.name = data.name;
						vm.cardno = data.id_number;
					},
					error: function(XMLHttpRequest, textStatus, error) {
						console.error('获取实名认证错误信息：' + XMLHttpRequest.status);
					}
				});

				$('.btn').on('tap', function() {
					mui.ajax(base + 'account/auth', {
						type: 'post',
						data: {
							'user': parseInt(plus.storage.getItem('user_id')),
							'name': $.trim($('.name').val()),
							'cardno': $.trim($('.cardno').val())
						},
						headers: sign(md5),
						dataType: 'json',
						success: function(data) {
							if(data.result) {
								var preid = plus.webview.currentWebview().preid;
								if(preid != null && preid != undefined) {
									plus.webview.getWebviewById(preid).evalJS('load()');
								}
								mui.alert('实名认证操作成功', '实名认证', function() {
									mui.back();
								});
							} else {
								mui.toast(data.message);
							}
						},
						error: function(XMLHttpRequest, textStatus, error) {
							console.error('实名认证操作错误信息：' + XMLHttpRequest.status);
						}
					});
				});
			});
		</script>
	</body>

</html>